package com.dai.zhenfujin.issue;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dai.zhenfujin.Constants.Constants;
import com.dai.zhenfujin.MainActivity;
import com.dai.zhenfujin.R;
import com.dai.zhenfujin.base.BaseFragment;
import com.dai.zhenfujin.bean.UserBean;
import com.dai.zhenfujin.http.CallBack;
import com.dai.zhenfujin.http.HttpClient;
import com.dai.zhenfujin.issue.activity.AlumIssueActivity2;
import com.dai.zhenfujin.my.activity.AlumTypeActivity;
import com.dai.zhenfujin.my.activity.MyActivity;
import com.dai.zhenfujin.my.activity.ReleaseActivity;
import com.dai.zhenfujin.utils.SPUtils;
import com.dai.zhenfujin.utils.UIUtils;
import com.orhanobut.logger.Logger;

import java.util.HashMap;
import java.util.Map;


/**
 * 发布
 */
public class IssueFragment2 extends BaseFragment implements View.OnClickListener {
    private View view;
    private ImageView imageView, ivReturn;
    private TextView tvTitleName,issue_history,tv_minqin;
    private TextView issue_major, issue_by_work;
    private String userId;

    @Override
    public View initView() {
        view = View.inflate(mContext, R.layout.fragment_issue, null);
        issue_major = view.findViewById(R.id.issue_major);   //主业
        issue_by_work = view.findViewById(R.id.issue_by_work); //副业
        issue_history = view.findViewById(R.id.issue_history); //副业
        tv_minqin = view.findViewById(R.id.tv_minqin);
        imageView = view.findViewById(R.id.title_imageview);
        tvTitleName = view.findViewById(R.id.title_textview);
        return view;
    }

    @Override
    public void initData() {
        super.initData();
       // getUserInfo();
        userId = SPUtils.getString(mContext,Constants.USER_MOBILE);
        tvTitleName.setText("发布产品和服务");
        imageView.setVisibility(View.GONE);
        imageView.setOnClickListener(this);
        issue_major.setOnClickListener(this);
        issue_by_work.setOnClickListener(this);
        issue_history.setOnClickListener(this);
        tv_minqin.setOnClickListener(this);
    }


    @Override
    public void onHiddenChanged(boolean hidden) { //这个方法会调用
        super.onHiddenChanged(hidden);
        Logger.d("EditCreateGroup-----" + "onHiddenChanged");
        if (!SPUtils.getBoolean(mContext,"getUserInfo")){

        }else {
           // issue_major.setVisibility(View.VISIBLE);
           // issue_by_work.setVisibility(View.VISIBLE);
        }
    }


    private void getUserInfo() {
        Map<String, Object> params = new HashMap<>();
        Map<String, String> params2 = new HashMap<>();
        params2.put("user_id","");
        params.put("req_bd",  params2);
        HttpClient.post(mContext, Constants.QUERYUSERINFO, params, new CallBack<UserBean>() {
            @Override
            public void onSuccess(UserBean resultBean) {
               // SPUtils.put(mContext,"getUserInfo",true);
               String user_job = resultBean.getUser_job();
               if (TextUtils.isEmpty(user_job)){
                   startActivity(new Intent(mContext, ReleaseActivity.class));
                   UIUtils.showToastSafe("请先完善名片信息");
                  // issue_major.setVisibility(View.INVISIBLE);
                 //  issue_by_work.setVisibility(View.INVISIBLE);
               }
            }
        });
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.issue_major://主业
                if (TextUtils.isEmpty(SPUtils.getConversionUserJob(getActivity(), userId))) {
                    startActivity(new Intent(getActivity(), ReleaseActivity.class));
                    UIUtils.showToastSafe("请先完善名片信息");
                    return;
                }
                Intent room = new Intent(getActivity(), AlumIssueActivity2.class);
                room.putExtra("type", 3);
                startActivity(room);
                break;
            case R.id.issue_by_work://副
                if (TextUtils.isEmpty(SPUtils.getConversionUserJob(getActivity(), userId))) {
                    //  getUserInfo();
                    startActivity(new Intent(getActivity(), ReleaseActivity.class));
                    UIUtils.showToastSafe("请先完善名片信息");
                    return;
                }
                Intent vehicle = new Intent(getActivity(), AlumTypeActivity.class);
                vehicle.putExtra("type", 2);
                startActivity(vehicle);
                break;
            case R.id.issue_history://历史记录
                Intent intent = new Intent(getActivity(), MyActivity.class);
                startActivity(intent);
                break;
            case R.id.tv_minqin://名片
                Intent intent2 = new Intent(getActivity(), ReleaseActivity.class);
                intent2.putExtra("userBean", MainActivity.userBean);
                startActivity(intent2);
                break;
        }
    }
}
